package com.relife.core.spring;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class SpringContextUtil implements ApplicationContextAware {
	private static ApplicationContext applicationContext;

	public void setApplicationContext(ApplicationContext act) throws BeansException {
		SpringContextUtil.applicationContext = act;
	}

	public static ApplicationContext getContext() {
		return applicationContext;
	}

	public static Object getService(String name) {
		if (applicationContext.containsBean(name))
			return applicationContext.getBean(name);
		else
			return null;
	}
}
